package com.bw.controller;

import com.alibaba.fastjson.JSONObject;
import com.bw.bean.UserInfo;
import com.bw.service.UserServiceImpl;
import netscape.javascript.JSObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author admin
 * @date 2025年09月19日 10:06
 */
@RestController
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/insert")
    public JSONObject insert(UserInfo userInfo){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg","插入");
        UserInfo userInfo1 = new UserInfo();
        userInfo1.setName("55");
        userInfo1.setPhoneNum("123");
        userInfo1.setEmail("555");
        userInfo1.setCreateTime(new Date());
        int insert = userService.insert(userInfo1);
        if(insert>0){
            jsonObject.put("code","1001");
        }else {
            jsonObject.put("code","1002");
        }
        return jsonObject;
    }
    @RequestMapping("/update")
    public JSONObject update(Integer id){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg","修改");
        int insert = userService.update(1);
        if(insert>0){
            jsonObject.put("code","1001");
        }else {
            jsonObject.put("code","1002");
        }
        return jsonObject;
    }
    @RequestMapping("/delect")
    public JSONObject delect(Integer id){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg","删除");
        int insert = userService.delect(1);
        if(insert>0){
            jsonObject.put("code","1001");
        }else {
            jsonObject.put("code","1002");
        }
        return jsonObject;
    }
    @RequestMapping("/selectAll")
    public List<UserInfo> selectAll(){
        return userService.selectAll();
    }
    @RequestMapping("/selectId")
    public List<UserInfo> selectId(){
        return userService.selectId(1);
    }
}
